// ****************************************************************
// Copyright 2012, Stephan Burguchev
// e-mail: me@sburg.net
// ****************************************************************
// *
using System;
using System.IO;
using Updater.Common;
using Updater.Updates;
using Version = Updater.Utils.Version;

namespace Updater.Tests
{
    public class TestDataProvider
    {
        public TestDataProvider(string tempDirectory)
        {
            this.TempDirectory = tempDirectory;

            this.ZipArchivePath = Path.Combine(Config.TestDataDirectory, "zip-archive-update.zip");
            this.UpdatesFeedUri = new Uri(Path.Combine(Config.TestDataDirectory, "simple-updates-rss.xml"));
            this.ApplicationDirectory = Path.Combine(this.TempDirectory, "ApplicationDir");
            this.UpdaterCacheDirectory = Path.Combine(this.TempDirectory, "UpdatesCacheDir");
            Directory.CreateDirectory(this.ApplicationDirectory);
            Directory.CreateDirectory(this.UpdaterCacheDirectory);
        }

        public string ApplicationDirectory { get; private set; }
        public string TempDirectory { get; private set; }
        public string UpdaterCacheDirectory { get; private set; }
        public Uri UpdatesFeedUri { get; private set; }
        public string ZipArchivePath { get; private set; }

        public Configuration CreateConfiguration()
        {
            return new Configuration
                {
                    ApplicationDirectory = this.ApplicationDirectory,
                    CurrentVersion = Version.Parse("1.0.0.0"),
                    UpdaterCacheDirectory = this.UpdaterCacheDirectory,
                    UpdatesFeedUri = this.UpdatesFeedUri
                };
        }

        public UpdateInformation CreateUpdateInformation1()
        {
            return new UpdateInformation(
                "title-1",
                "description-1",
                null,
                Version.Parse("2.0.0.0"),
                DateTime.Now.AddDays(-30),
                new Uri(this.ZipArchivePath),
                666,
                typeof(ZipArchiveUpdate),
                ChecksumHelper.ComputeFileChecksum(this.ZipArchivePath, ChecksumType.Sha1),
                ChecksumType.Sha1);
        }

        public UpdateInformation CreateUpdateInformation2()
        {
            return new UpdateInformation(
                "title-2",
                "description-2",
                null,
                Version.Parse("3.0.0.0"),
                DateTime.Now.AddDays(-20),
                new Uri(this.ZipArchivePath),
                666,
                typeof(ZipArchiveUpdate),
                ChecksumHelper.ComputeFileChecksum(this.ZipArchivePath, ChecksumType.Sha1),
                ChecksumType.Sha1);
        }
    }
}
